package net.fpeg.kotlin.msa.auth.controller

import net.fpeg.kotlin.msa.auth.dto.BaseDto
import net.fpeg.kotlin.msa.auth.dto.LoginDto
import net.fpeg.kotlin.msa.auth.service.AuthService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@RestController
class AuthController {
    @Autowired
    lateinit var authService: AuthService

    @PostMapping("/register")
    fun register(@RequestBody loginDto: LoginDto) = authService.register(loginDto).username.let { BaseDto(it) }


    @PostMapping("/login")
    fun login(@RequestBody loginDto: LoginDto) = BaseDto(authService.login(loginDto))
}